	package cs4383;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Switch;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Vector3d;

import org.apache.log4j.Logger;

import ar.MarkerModel;

public class CustomMarkerModel extends MarkerModel {

	Logger logger = Logger.getLogger(this.getClass());
	private Furniture furniture;
	private Transform3D t3d = new Transform3D();
	private Vector3d translationV = new Vector3d();

	private double angle = 0.0;
	private double scale = 1.0;

	public Furniture getFurniture() {
		return furniture;
	}

	public void setFurniture(Furniture f) {
		Switch s = this.getVisSwitch();
		s.removeAllChildren();
		this.furniture = f;
		BranchGroup bg = f.getBranchGroup();
		s.addChild(bg);
		TransformGroup modelTg = (TransformGroup) bg.getChild(0);
		logger.debug("modelTg " + modelTg);
		this.setModelTg(modelTg);
		this.transform();
	}

	public CustomMarkerModel(String markerFnm, String modelFnm, double scale,
			boolean hasCoords) {
		super(markerFnm, modelFnm, scale, hasCoords);
	}
	
	public void rotateClockwise(double a){
		this.angle -= a;
		transform();
	}
	
	public void rotateAntiClockwise(double a){
		this.angle += a;
		transform();
	}

	public void rotateZ(double angle) {
		this.angle = angle;
		transform();
	}

	public void setScale(double s) {
		this.scale = s;
		transform();
	}
	
	public void scaleUp(double s){
		this.scale += s;
		transform();
	}
	
	public double getScale(){
		return scale;
	}
	
	public void scaleDown(double s){
		this.scale -= s;
		transform();
	}

	private void transform() {
		t3d.rotZ(angle);
		t3d.setScale(scale);
		t3d.setTranslation(translationV);
		TransformGroup tg = this.getModelTg();
		logger.debug("transform() modelTg " + tg);
		tg.setTransform(t3d);
	}

	public void moveX(double x) {
		translationV.setX(x);
		transform();
	}

	public void moveY(double y) {
		translationV.setY(y);
		transform();
	}
}
